/**
 * Create in 2012-4-25.
 */
package kit4j.ui.cs.component;

import java.util.Calendar;
import java.util.Date;

/**
 * 日期时间选择器组件基本实现。
 * 
 * @author MiniKnife
 *
 */
public class DateChooserImpl implements DateChooser {
	
	private Calendar calendar;
	
	public DateChooserImpl() {
		init();
	}
	
	public DateChooserImpl(Date date) {
		init();
		setDate(date);
	}
	
	private void init() {
		calendar = Calendar.getInstance();
	}

	/**
	 * @see kit4j.ui.cs.component.DateChooser#getDate()
	 */
	@Override
	public Date getDate() {
		return calendar.getTime();
	}

	/**
	 * @see kit4j.ui.cs.component.DateChooser#setDate(java.util.Date)
	 */
	@Override
	public void setDate(Date date) {
		calendar.setTime(date);
	}

	/**
	 * @see kit4j.ui.cs.component.DateChooser#getYear()
	 */
	@Override
	public int getYear() {
		return calendar.get(Calendar.YEAR);
	}

	/**
	 * @see kit4j.ui.cs.component.DateChooser#setYear(int)
	 */
	@Override
	public void setYear(int year) {
		calendar.set(Calendar.YEAR, year);
	}

	/**
	 * @see kit4j.ui.cs.component.DateChooser#getMonth()
	 */
	@Override
	public int getMonth() {
		return calendar.get(Calendar.MONTH) + 1;
	}

	/**
	 * @see kit4j.ui.cs.component.DateChooser#setMonth(int)
	 */
	@Override
	public void setMonth(int month) {
		calendar.set(Calendar.MONTH, month - 1);
	}

	/**
	 * @see kit4j.ui.cs.component.DateChooser#getDayOfMonth()
	 */
	@Override
	public int getDayOfMonth() {
		return calendar.get(Calendar.DAY_OF_MONTH);
	}

	/**
	 * @see kit4j.ui.cs.component.DateChooser#setDayOfMonth(int)
	 */
	@Override
	public void setDayOfMonth(int day) {
		calendar.set(Calendar.DAY_OF_MONTH, day);
	}

}
